home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / audio / drive / Render.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.0 KB  |  218 lines

  1. /*
  2.  * Copyright 1992-1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. //////////////////////////////////////////////////////////////////////
  18. // Render.c++ - implimentation of the render class
  19. //////////////////////////////////////////////////////////////////////
  20.  
  21. #include "Render.h"
  22.  
  23. void init_render()
  24. {
  25.     init_colormaps();
  26.     
  27.     // set up lighting
  28.     static float grey_plastic[] = {
  29.         AMBIENT, 0.1, 0.1, 0.1,
  30.         DIFFUSE, 0.5, 0.5, 0.5,
  31.         SPECULAR, 0.8, 0.8, 0.8,
  32.         SHININESS, 10.0,
  33.         LMNULL};
  34.  
  35.     static float blue_plastic[] = {
  36.         AMBIENT, 0.1, 0.1, 0.1,
  37.         DIFFUSE, 0.1, 0.1, 0.5,
  38.         SPECULAR, 0.4, 0.4, 0.4,
  39.         SHININESS, 10.0,
  40.         LMNULL};
  41.  
  42.     static float black_plastic[] = {
  43.         AMBIENT, 0.1, 0.1, 0.1,
  44.         DIFFUSE, 0.1, 0.1, 0.1,
  45.         SPECULAR, 0.4, 0.4, 0.4,
  46.         SHININESS, 10.0,
  47.         LMNULL};
  48.  
  49.     static float charcoal[] = {
  50.         AMBIENT, 0.1, 0.1, 0.1,
  51.         DIFFUSE, 0.3, 0.3, 0.3,
  52.         SPECULAR, 0.5, 0.5, 0.5,
  53.         SHININESS, 20.0,
  54.         LMNULL};
  55.  
  56.     static float asphalt[] = {
  57.         DIFFUSE, 0.05, 0.05, 0.05,
  58.         LMNULL};
  59.  
  60.     static float yellow_asphalt[] = {
  61.         DIFFUSE, 0.8, 0.8, 0.0,
  62.         SPECULAR, 0.1, 0.1, 0.0,
  63.         SHININESS, 1.0,
  64.         LMNULL};
  65.  
  66.     static float white_metal[] = {
  67.         AMBIENT, 0.1, 0.1, 0.1,
  68.         DIFFUSE, 0.7, 0.7, 0.8,
  69.         SPECULAR, 0.8, 0.8, 0.8,
  70.         SHININESS, 30.0,
  71.         LMNULL};
  72.  
  73.     static float red_metal[] = {
  74.         AMBIENT, 0.5, 0.0, 0.0,
  75.         DIFFUSE, 0.7, 0.0, 0.0,
  76.         SPECULAR, 1.0, 1.0, 1.0,
  77.         SHININESS, 50.0,
  78.         LMNULL};
  79.  
  80.     static float chrome[] = {
  81.         AMBIENT, 0.1, 0.1, 0.1,
  82.         DIFFUSE, 0.6, 0.6, 0.6,
  83.         SPECULAR, 0.8, 0.8, 0.8,
  84.         SHININESS, 30.0,
  85.         LMNULL};
  86.         
  87.     static float grey_rubber[] = {
  88.         AMBIENT, 0.2, 0.2, 0.2,
  89.         DIFFUSE, 0.5, 0.5, 0.5,
  90.         LMNULL};
  91.  
  92.     static float wood[] = {
  93.         AMBIENT, 0.1, 0.1, 0.1,
  94.         DIFFUSE, 0.46, 0.29, 0.0,
  95.         LMNULL};
  96.  
  97.     static float leaves[] = {
  98.         AMBIENT, 0.1, 0.1, 0.1,
  99.         DIFFUSE, 0.0, 0.8, 0.1,
  100.         LMNULL};
  101.  
  102.     static float grey_metal[] = {
  103.         AMBIENT, 0.2, 0.2, 0.2,
  104.         DIFFUSE, 0.5, 0.5, 0.5,
  105.         SPECULAR, 1.0, 1.0, 1.0,
  106.         SHININESS, 50.0,
  107.         LMNULL};
  108.  
  109.     static float dome_light[] = {
  110.         LCOLOR, 1.0, 1.0, 1.0,
  111.         POSITION, 0.0, 1.0, 1.0, 0.0,
  112.         LMNULL};
  113.  
  114.     static float sun[] = {
  115.         AMBIENT, 0.3, 0.3, 0.3,
  116.         LCOLOR, 1.0, 1.0, 1.0,
  117.         POSITION, 1.0, 0.7, 0.3, 0.0,
  118.         LMNULL};
  119.  
  120.     lmdef(DEFLMODEL, 1, 0, (float *)NULL);
  121.     
  122.     lmdef(DEFLIGHT, SUN, np(sun), sun);
  123.     lmdef(DEFLIGHT, DOME_LIGHT, np(dome_light), dome_light);
  124.     
  125.     lmdef(DEFMATERIAL, GREY_PLASTIC, np(grey_plastic), grey_plastic);
  126.     lmdef(DEFMATERIAL, BLACK_PLASTIC, np(black_plastic), black_plastic);
  127.     lmdef(DEFMATERIAL, RED_METAL, np(red_metal), red_metal);
  128.     lmdef(DEFMATERIAL, CHROME, np(chrome), chrome);
  129.     lmdef(DEFMATERIAL, CHARCOAL, np(charcoal), charcoal);
  130.     lmdef(DEFMATERIAL, ASPHALT, np(asphalt), asphalt);
  131.     lmdef(DEFMATERIAL, YELLOW_ASPHALT, np(yellow_asphalt), yellow_asphalt);
  132.     lmdef(DEFMATERIAL, GREY_RUBBER, np(grey_rubber),grey_rubber);
  133.     lmdef(DEFMATERIAL, WOOD, np(wood), wood);
  134.     lmdef(DEFMATERIAL, LEAVES, np(leaves), leaves);
  135.     lmdef(DEFMATERIAL, GREY_METAL, np(grey_metal), grey_metal);
  136.  
  137.  
  138.     // initialize the font manager
  139.     fminit();
  140.  
  141.     // initialize patterns
  142.     static unsigned short holes1[16] = {
  143.         0x5555, 0xAAAA,    0x5555, 0xAAAA,
  144.         0x5555, 0xAAAA,    0x5555, 0xAAAA,
  145.         0x5555, 0xAAAA,    0x5555, 0xAAAA,
  146.         0x5555, 0xAAAA,    0x5555, 0xAAAA};
  147.  
  148.     /*
  149.     static unsigned short holes2[16] = {
  150.         0x3333, 0xCCCC, 0x3333, 0xCCCC,
  151.         0x3333, 0xCCCC, 0x3333, 0xCCCC,
  152.         0x3333, 0xCCCC, 0x3333, 0xCCCC,
  153.         0x3333, 0xCCCC, 0x3333, 0xCCCC};
  154.     */
  155.     
  156.     defpattern(HOLES, 16, holes1);
  157. }
  158.  
  159.  
  160.  
  161. // sweeps the segment defined by r-s counter-clockwise by angle
  162. void sweep(float r[2], float s[2], float angle)
  163. {
  164.     float last_p[2], last_q[2];
  165.  
  166.     last_p[0] = r[0];
  167.     last_p[1] = r[1];
  168.     last_q[0] = s[0];
  169.     last_q[1] = s[1];
  170.     
  171.     for (float theta = 1.0; theta <= angle; theta += 1.0)
  172.     {
  173.         float p[2], q[2];
  174.  
  175.         float cos = fcos(theta*M_PI/180.0);
  176.         float sin = fsin(theta*M_PI/180.0);
  177.         
  178.         p[0] = r[0]*cos - r[1]*sin;
  179.         p[1] = r[0]*sin + r[1]*cos;
  180.  
  181.         q[0] = s[0]*cos - s[1]*sin;
  182.         q[1] = s[0]*sin + s[1]*cos;
  183.  
  184.         bgnpolygon();
  185.             v2f(last_q);
  186.             v2f(last_p);
  187.             v2f(p);
  188.             v2f(q);
  189.         endpolygon();
  190.         
  191.         last_p[0] = p[0];
  192.         last_p[1] = p[1];
  193.         last_q[0] = q[0];
  194.         last_q[1] = q[1];
  195.     }
  196. }
  197.  
  198. void init_colormaps()
  199. {
  200.     // set up overlay colors
  201.     drawmode(PUPDRAW);
  202.     mapcolor(CLEAR, 0, 0, 0);
  203.     mapcolor(GREY1, 64, 64, 64);
  204.     mapcolor(GREY2, 127, 127, 127);
  205.     mapcolor(GREY3, 192, 192, 192);
  206.     drawmode(NORMALDRAW);
  207.  
  208. }
  209.  
  210.  
  211. void vertex(float a, float b)
  212. {
  213.     float v[2];
  214.     v[0] = a; v[1] = b;
  215.     v2f(v);
  216. }
  217.  
  218.